package main.java.dao.impl;

import main.java.dao.BaseDAO;
import main.java.dao.UserDao;
import main.java.polo.User;

public class UserDaoImpl extends BaseDAO implements UserDao {
    @Override
    public int insertBasic(User user) {
        try {
            String sql = "insert into t_user (user_name, user_password) values (?,?)";
            return executeUpdate(sql, user.getUserName(), user.getUserPassword());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int update(User user) {
        try {
            String sql = "update t_user set user_Number = ?, user_phone= ? where user_name= ?";
            return executeUpdate(sql,  user.getUserNumber(), user.getUserPhone(),user.getUserName());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public User selectByNameAndPassword(String userName, String userPassword) {
        try {
            String sql = "select user_name userName,user_password userPassword from t_user where user_name = ? and user_password = ?";
            return executeQuerySingle(User.class, sql, userName, userPassword);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public User selectByName(String userName) {
        try {
            String sql = "select status userStatus from t_user where user_name= ?";
            return executeQuerySingle(User.class, sql, userName);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


}
